//index.js
//获取应用实例
let app = getApp()
let formatTime = require('../../utils/util.js')
Page({
  data: {
    logisticsTraces: [{ AcceptTime: formatTime.formatTime(new Date()), AcceptStation: '订单尚未发货' }],
    LogisticCode: '',
    deliveryName: ''
  },
  onLoad: function (e) {
    var orderId = e.id
    this.data.orderId = orderId
    this.getLogictiscDetails(orderId)

  },
  onShow: function () {
    var that = this;
  },

  /**
   * 获取物流详情
   */
  getLogictiscDetails: function (orderID) {
    let token = wx.getStorageSync('token')
    let that = this
    wx.request({
      url: app.apiUrl('/order/express'),
      method: 'GET',
      header: {
        "Authorization": 'Bearer ' + token
      },
      data: {
        order_id: orderID,
      },
      success: function (res) {
        console.log('getExpress')
        console.log(res.data)
        if (res.data.data) {
          that.setData({
            LogisticCode: res.data.data.LogisticCode,
            logisticsTraces: res.data.data.Traces.reverse(),
            deliveryName: res.data.data.delivery_company_name 
          })
        }

      },
      fail: function (res) {
        console.log(res)
      },
      complete: function (res) {
        // wx.hideToast()
        //console.log(res)
      }
    })
  }
})
